package com.mcms.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.mcms.service.common.DealResult;
import com.mcms.service.dw.AddCustomBasicInfoService;
import com.mcms.service.dw.AddCustomInquiryInfoService;
import com.mcms.service.dw.AddSubscribeDoctorInfoService;
import com.mcms.util.DBHelper;
import com.mcms.web.vo.DWZResult;

/**
 * 针对客户信息的各种交易处理逻辑
 * @author 
 */
public class CustomCheckService {

public static void execute(HttpServletRequest request){
		
		boolean isSuc = true;
		request.setAttribute("message", "无重复信息");
//		request.setAttribute("tabId", request.getParameter("tabId"));
		String actionType = request.getParameter("actionType");// 处理类别
		String custName = request.getParameter("CUSTOM_NAME");// 客户姓名
		String custPhone = request.getParameter("TELEPHONE_NO");// 客户手机
		String idCard = request.getParameter("idCard");// 身份证号码
		
		// 执行验证
		try {
			String sqlStr = "SELECT CUSTOM_ID FROM MCMS_CUSTOM_INFO WHERE CUSTOM_NAME='"+custName+"' OR TELEPHONE_NO='"+custPhone+"'";
			DBHelper dbh = DBHelper.getInstance();
			List i = dbh.query(sqlStr);
			if(i.size() > 0){
				isSuc = false;
				request.setAttribute("message", "此姓名或手机号已经存在");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			isSuc = false;
			request.setAttribute("message", "查询信息失败");
		}
		
		//处理结果
		request.setAttribute("tabId", "page");
		
		DealResult.execute(request,isSuc);
	}
	
	public static void dealResult(HttpServletRequest request,boolean isSuc){
		DWZResult dwzResult = new DWZResult();//"message":"操作成功", "navTabId":"navNewsLi", "forwardUrl":"", "callbackType":"closeCurrent"}
		dwzResult.setNavTabId("page");
//		dwzResult.setRel("page_sc1"); 
		dwzResult.setMessage("操作成功");  
		dwzResult.setStatusCode("200");  
//		dwzResult.setCallbackType("closeCurrent");  
//		dwzResult.setForwardUrl("customList.html?userName=aaa&deptCode=sc&actionType=listCustom");
		
		request.setAttribute("dwzResult", dwzResult);
	}
}
